﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace iSufeMVC4.Qiancun
{
    public static class QcSerive
    {
        public static List<DimStudent> GetStudentByCode(string code)
        {
            using (QianCunDWDataContext db = new QianCunDWDataContext())
            {
                return db.DimStudent.Where(p => p.StudentCode == code).ToList();
            }
        }
        public static DimGeography GetGeographyByKey(int key)
        {
            using (QianCunDWDataContext db = new QianCunDWDataContext())
            {
                return db.DimGeography.Where(p => p.GeographyKey == key).FirstOrDefault();
            }
        }
        public static List<DimGeography> GetGeographyByWord(string text,int count)
        {
            using (QianCunDWDataContext db = new QianCunDWDataContext())
            {
                return db.DimGeography.Where(p => 
                    (p.BigAreaName.Contains(text)||
                    p.ProvinceName.Contains(text)||
                    p.CityName.Contains(text)||
                    p.AreaName.Contains(text)||
                    p.TownName.Contains(text)||
                    p.VillageName.Contains(text)) 
                    && (p.VillageName!="unknown" || p.TownName!="unknown")
                ).Take(count).ToList();
            }
        }

        
        public static int GetFactTextAnswerCount(int year,int student)
        {
            using (QianCunDWDataContext db = new QianCunDWDataContext())
            {
                return db.FactTextAnswer.Where(p => 
                    p.StudentKey == student && 
                    p.YearKey==year
                    ).Count();
            }
        }
    }
}
